import { getAllAppList} from "@/api/common/index-adv.js";

export default {
  dicts: ['sys_channel', 'ACCOUNT_AGENT'],
  data () {
    return {
      // 产品数据
      productList: [],
      // 渠道
      channelList: [],
      // 默认排序
      defaultSort: {prop: 'acdate', order: 'desc'},
      // 遮罩层
      loading: false,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      tableHeight: 500,
    }
  },
  mounted() {
    let elTable = document.querySelector('.el-table');
    if (elTable) {
      this.tableHeight = document.body.clientHeight - elTable.offsetTop - 150;
    }
    // window.onresize = () => {
    //   setTimeout(() => {
    //     this.tableHeight = document.body.clientHeight - elTable.offsetTop - 150;
    //   }, 300);
    // }
  },
  methods: {
    _getProductList() {
      getAllAppList().then(response => {
        this.productList = response.data.map(item => {
          return {
            id: item.id,
            appcode: item.appcode,
            name: item.appname,
            value: item.apppkg
          }
        })
      })
    },
    _productChange (newValue) {},
    _channelChange(newValue) {},
    _agentChange(newValue) {},
    // 表头排序
    _changeSort (column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList()//调用列表
    },
    // 整合参数
    _integrationParams () {
      let vm = this
      if (!vm.queryParams.orderByColumn) vm.queryParams.orderByColumn = vm.defaultSort.prop;
      if (!vm.queryParams.isAsc) vm.queryParams.isAsc = vm.defaultSort.order;
      if (vm.queryParams.dateRange && vm.queryParams.dateRange.length) {
        let bData = vm.queryParams.dateRange[0].replace(/-/g, '').replace(/\s+/g,"");
        let eData = vm.queryParams.dateRange[1].replace(/-/g, '').replace(/\s+/g,"");
        vm.queryParams.beginDate = bData.substr(0, 8);
        vm.queryParams.endDate = eData.substr(0, 8);
        if (vm.queryParams.dataType == '1') {
          vm.queryParams.beginHour = bData.substr(8, 10);
          vm.queryParams.endHour = eData.substr(8, 10);
        } else {
          vm.queryParams.beginHour && delete vm.queryParams.beginHour;
          vm.queryParams.endHour && delete vm.queryParams.endHour;
        }
      } else {
        vm.queryParams.beginDate = '';
        vm.queryParams.endDate = '';
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.$refs["queryForm"].validate(valid => {
        if (valid) {
          this.queryParams.disableSearch = true;
          this.queryParams.pageNum = 1;
          this._integrationParams();
          this.getList();
          setTimeout(() => {
            this.queryParams.disableSearch = false;
          }, 3000);
        }
      })
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
}
